package com.xyz.controller;

import com.xyz.aop.Param;
import com.xyz.service.RoleAppService;
import com.xyz.util.dto.DataResult;
import com.xyz.util.dto.LoginInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("system")
public class RoleAppController {

    private static final Logger logger = LoggerFactory.getLogger(RoleAppController.class);

    @Autowired
    private RoleAppService roleAppService;

    @PostMapping("selectAppUserInfo")
    public DataResult selectAppUserInfo(
            LoginInfo li
    ) {
        try {
            return roleAppService.selectAppUserInfo(li);
        } catch (Exception e) {
            logger.error("selectAppUserInfo", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectAppDirectoryByRoleId")
    public DataResult selectAppDirectoryByRoleId(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String roleId
    ) {
        try {
            return roleAppService.selectAppDirectoryByRoleId(li, Long.parseLong(roleId));
        } catch (Exception e) {
            logger.error("selectAppDirectoryByRoleId", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("updateAppDirectoryByRoleId")
    public DataResult updateAppDirectoryByRoleId(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String roleId,
            @Param(isRequired = false) String directoryIds
    ) {
        try {
            return roleAppService.updateAppDirectoryByRoleId(li, Long.parseLong(roleId), directoryIds);
        } catch (Exception e) {
            logger.error("updateAppDirectoryByRoleId", e);
            return DataResult.build9500();
        }
    }

}
